home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
gc
/
GCfast_malloc.s
< prev
next >
Wrap
Text File
|
1991-08-09
|
3KB
|
140 lines
/* A faster version of the standard PCR allocator on SPARCS. Does not */
/* handle allocator callbacks. Does not maintain GC_objects_allocd. */
/* Instead of fully acquiring the allocation monitor lock, we only */
/* acquire the associated spin lock. */
/* We assume a version of SunOS 4.1 (or later) with the ldstub patch. */
/* We round the size up to a multiple of 8. Otherwise no attempt is */
/* made to merge object sizes. */
# define ML_LOCK_OFF 0 /* Must be consistent with Threads.h */
# define ML_HOLDER_OFF 8 /* Must be consistent with Threads.h */
# define MAXOBJSZ 2048 /* Must be consistent with GCPrivate.h */
.global _GC_words_allocd
.global _GC_objfreelist
.global _GC_allocate_ml
.global _GC_malloc
.global _GC_fast_malloc
_GC_fast_malloc:
sethi %hi(_GC_allocate_ml),%o1
cmp %o0,MAXOBJSZ
bg failed_wo_lock
or %o1,%lo(_GC_allocate_ml),%o1
! Attempt to acquire _GC_allocate_ml spin lock
ldstub [%o1+ML_LOCK_OFF],%o2
ld [%o1+ML_HOLDER_OFF],%o5
tst %o2
bnz failed_wo_lock
! Round up the size suitably
add %o0,7,%o3 ! delay slot OK
andn %o3,7,%o3
! Get the free list entry
sethi %hi(_GC_objfreelist),%o2
or %o2,%lo(_GC_objfreelist),%o2
ld [%o3+%o2],%o4
! Is someone in the monitor?
tst %o5
bnz failed_w_lock
! Was free list nonempty?
tst %o4 ! delay slot OK
bnz,a success
ld [%o4],%o5
failed_w_lock:
set _GC_malloc,%o2
jmp %o2
st %g0,[%o1+ML_LOCK_OFF]
failed_wo_lock:
set _GC_malloc,%o2
jmp %o2
nop
success:
! Update the free list entry
not %o5,%o5
st %o5,[%o2+%o3]
! Update GC_words_allocd and clear the link field in the object
sethi %hi(_GC_words_allocd),%o2
ld [%o2+%lo(_GC_words_allocd)],%o5
st %g0,[%o4]
sra %o3,2,%o3
add %o5,%o3,%o5
st %o5,[%o2+%lo(_GC_words_allocd)]
! return (%o4)
mov %o4,%o0
retl
! Release spin lock
st %g0,[%o1+ML_LOCK_OFF] ! delay slot
.global _GC_aobjfreelist
.global _GC_malloc_atomic
.global _GC_fast_malloc_atomic
_GC_fast_malloc_atomic:
sethi %hi(_GC_allocate_ml),%o1
cmp %o0,MAXOBJSZ
bg atomic_failed_wo_lock
or %o1,%lo(_GC_allocate_ml),%o1
! Attempt to acquire _GC_allocate_ml spin lock
ldstub [%o1+ML_LOCK_OFF],%o2
ld [%o1+ML_HOLDER_OFF],%o5
tst %o2
bnz atomic_failed_wo_lock
! Round up the size suitably
add %o0,7,%o3 ! delay slot OK
andn %o3,7,%o3
! Get the free list entry
sethi %hi(_GC_aobjfreelist),%o2
or %o2,%lo(_GC_aobjfreelist),%o2
ld [%o3+%o2],%o4
! Is someone in the monitor?
tst %o5
bnz atomic_failed_w_lock
! Was free list nonempty?
tst %o4 ! delay slot OK
bnz,a atomic_success
ld [%o4],%o5
atomic_failed_w_lock:
set _GC_malloc_atomic,%o2
jmp %o2
st %g0,[%o1+ML_LOCK_OFF]
atomic_failed_wo_lock:
set _GC_malloc_atomic,%o2
jmp %o2
nop
atomic_success:
! Update the free list entry
not %o5,%o5
st %o5,[%o2+%o3]
! Update GC_words_allocd and clear the link field in the object
sethi %hi(_GC_words_allocd),%o2
ld [%o2+%lo(_GC_words_allocd)],%o5
st %g0,[%o4]
sra %o3,2,%o3
add %o5,%o3,%o5
st %o5,[%o2+%lo(_GC_words_allocd)]
! return (%o4)
mov %o4,%o0
retl
! Release spin lock
st %g0,[%o1+ML_LOCK_OFF] ! delay slot